<?php

/*

This bad boy will get a user name and password, then forward it to newentry.php to fill in the key info.

*/

$thehtml="
<html>
<head>
    <title>Enter New User</title>
</head>

<body>

<h1>Log in</h1>

<p>Please enter your username and password.</p>

<form method=\"post\" name=\"grabuser\" action=\"getenteruser.php\">

<br />Username: <input type=\"text\" name=\"username\" value=\"\">

<br />Password: <input type=\"password\" name=\"password\" value=\"\">
	
<input type=\"Submit\" name=\"action\" value=\"Submit\">


</form>
</body>
</html>";


// Post information to this page and process

if ($_POST['action'] == "Submit") {
    extract ($_POST);
	
	/* Hash the password */
	$password = MD5($password);
	
	// Grab data from DB
	require("./dbconnect.inc.php");
	
	// Process
	mysql_connect($host,$dbuser,$dbpassword);
	@mysql_select_db($database) or die( "Unable to select database");

	// Grab data
	$datagrab=sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'", mysql_real_escape_string($username), mysql_real_escape_string($password));


	$dataresult=mysql_query($datagrab);
	$numdata=mysql_numrows($dataresult);

	$j=0;
	while($j < $numdata){
	$pk_e=mysql_result($dataresult,$j,"pk_e");
	$pk_n=mysql_result($dataresult,$j,"pk_n");
	$j++;
	}
	
	// redirect url
	$url="newentry.php?pk_e=$pk_e&pk_n=$pk_n&username=$username";
	
	$redirectfirst="
	<html>
		<head>
		<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=";
	
	$redirectsecond="
	\">
		</head>
	</html>";
	
	echo $redirectfirst."".$url."".$redirectsecond;
}

else{
	echo $thehtml;
	}

?>